package cc.lucien.demo02;

public class Student implements Comparable<Student>{
    private String name;
    private int score;

    public Student(String name, int score){
        this.name = name;
        this.score = score;
    }

    @Override
    public int compareTo(Student another) {
//        if (this.score < another.score)
//            return -1;
//        else if (this.score == another.score)
//            return 0;
//        return 1;
        //可以这样写
        return this.score - another.score;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null)
            return false;
        if (this.getClass() != o.getClass())
            return false;
        Student stu = (Student) o;
        return stu.name.equalsIgnoreCase(this.name);
    }

    @Override
    public int hashCode() {
        int h = 0;
        h+= 31 * h + name.hashCode();
        return h;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}
